clear

/*import dataset*/

 import excel "C:\Users\efren\Dropbox\Mi computadora\Desktop\Kim-Perez-Rogbeer project\Data - Study 2 Blks-Lats\Study 2.xlsx", sheet("Stress+Testing+Black-Latino+Coa") firstrow

****************************************
*****code pretreatment demographics*****
****************************************

*race

encode Race, gen (black1)
tab black1
tab black1, nolabel
gen black=0
recode black(0=1) if black1==2
drop if black==0
tab black

*ideology

encode Ideology, gen(ideology1)
tab ideology1, nolabel
recode ideology1 (8=.)(9=.)
summ ideology1

*age

encode Age, gen(age1)
summ age1
gen age=(age1+17)
summ age

*education

encode Education, gen(educ1)
gen college=0
recode college(0=1) if educ==4
tab college 

*gender

encode Gender, gen(gender1)
gen male=0
recode male(0=1) if gender1==1
tab male

*republican

encode Partisanship, gen(partyID)
tab partyID

gen republican=0
recode republican(0=1) if partyID==2
tab republican

*********************************************************
*****code first manipulation - shared discrimination*****
*********************************************************

encode Control_Turtle, gen(control1)
tab control1

encode SharedDisc, gen(discrim1)
tab discrim1
tab discrim1, nolabel

gen shareddisc=.
recode shareddisc(.=0) if control1==1
recode shareddisc(.=1) if discrim1==1
tab shareddisc

***************************************
*****code first manipulation check*****
***************************************

encode QC_TC, gen(checkc)
tab checkc

encode QC_SD, gen(checkt)
tab checkt

gen mcheck=.

recode mcheck(.=0) if checkc==2
recode mcheck(.=0) if checkt==2

recode mcheck(.=1) if checkc==1
recode mcheck(.=1) if checkt==1

tab mcheck

*******************************
*****code solidarity items*****
*******************************

encode Solidarity_Bond, gen(bond)
tab bond, nolabel
recode bond(6=.)(7=.)
summ bond

encode Solidarity_Allies, gen(allies)
tab allies, nolabel
recode allies(6=.)(7=.)
summ allies

encode Solidariy_CFate, gen(fate)
tab fate, nolabel
recode fate(6=.)(7=.)
summ fate

pwcorr bond allies fate, sig
alpha bond allies fate, std

gen solidarity1=(bond+allies+fate)/3
gen solidarity=(solidarity-1)/4
summ solidarity

****************************************************
*****code second manipulation - distinctiveness*****
****************************************************

encode Incommensurate, gen(dissimilar1)
tab dissimilar1
tab dissimilar1, nolabel
recode dissimilar1 (2=.)(3=.)

gen dissimilar=dissimilar1
recode dissimilar(.=0) if shareddisc==1
recode dissimilar(.=0) if shareddisc==0

tab dissimilar

*generate interaction between mediator and downstream manipulation

gen soliddiss=(solidarity*dissimilar)

***********************
*****code outcomes*****
***********************

encode Latino_1, gen(lathate1)
tab lathate1, nolabel
recode lathate1(6=.)(7=.)
summ lathate1

encode Latino_2R, gen(latborder1)
tab latborder1
recode latborder1 (6=.)(7=.)
recode latborder1 (1=5)(2=4)(3=3)(4=2)(5=1)
summ latborder1

encode Latino_3, gen(daca1)
tab daca1
recode daca1 (6=.)(7=.)
summ daca1

encode Latino_4, gen(lataffirm1)
tab lataffirm1
recode lataffirm1(6=.)(7=.)
summ lataffirm1

pwcorr lathate1 latborder1 daca1 lataffirm1, sig
alpha lathate1 latborder1 daca1 lataffirm1, std

*reverse worded item, latborder1, performs poorly. Drop it. 

pwcorr lathate1 latborder1 daca1 lataffirm1, sig
alpha lathate1 latborder1 daca1 lataffirm1, std

*scale three remaining items

gen prolat1=(lathate1+daca1+lataffirm1)/3
gen prolat=(prolat1-1)/4
summ prolat

*per reviewer 1, include all items in pro-Latino scale

gen prolat2=(lathate1+latborder1+daca1+lataffirm1)/4
summ prolat2
gen prolatall=(prolat2-1)/4
summ prolatall

alpha lathate1 latborder1 daca1 lataffirm1, std
alpha lathate1 daca1 lataffirm1, std

****************************************************************************
*****manipulation check passage rate (shared discrimination treatment)******
****************************************************************************

tab mcheck

****************************************************************************
*****manipulation check passage rate (distinctiveness threat treatment)*****
****************************************************************************

tab QC_Incom

*******************************************************************
*****report scale reliability and average level for solidarity*****
*******************************************************************

alpha bond allies fate, std

summ solidarity

/*estimate T to M*/

*T = treatment
*M = mediator

reg solidarity shareddisc
ttest solidarity, by(shareddisc)

*divide difference by pooled standard deviation = Cohen's d

***Significant Cohen's d ~ .37

*************************
*****Table 1 results*****
*************************

*model includes direct treatment effect on prolat; notice it is substantively and statistically zero

sem (solidarity <- shareddisc ideology1)(prolat <- solidarity shareddisc dissimilar soliddiss ideology1)

*per reviewer 1 - interactions between treatments

gen treat12=(shareddisc*dissimilar)

reg prolat shareddisc dissimilar treat12, robust

test shareddisc dissimilar treat12 

lincom shareddisc+treat12*0
lincom shareddisc+treat12*1

lincom dissimilar+treat12*0
lincom dissimilar+treat12*1

*******************************************************************
*****balance table in Supplementary Material, Section 1 (SM.1)*****
*******************************************************************

*for shared discrimination manipulation 

ttest age, by(shareddisc)
ttest male, by(shareddisc)
ttest college, by(shareddisc)
ttest ideology1, by(shareddisc)
ttest republican, by(shareddisc)

*for distinctiveness threat manipulation

ttest age, by(dissimilar)
ttest male, by(dissimilar)
ttest college, by(dissimilar)
ttest ideology1, by(dissimilar)
ttest republican, by(dissimilar)

*******************************************************
*****model with full prolat scale, i.e., prolatall*****
*******************************************************

sem (solidarity <- shareddisc ideology1)(prolatall <- solidarity shareddisc dissimilar soliddiss ideology1)

*************************************************
*****Average Direct Effects (ADEs) in (SM.6)*****
*************************************************

reg prolat dissimilar shareddisc

reg solidarity shareddisc

